package io.sage.modules.employer.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.plugins.Page;

import io.sage.common.utils.PageUtils;
import io.sage.modules.exam.enums.ExamEnum;
import io.sage.modules.employer.dao.PostMapper;
import io.sage.modules.employer.entity.Post;
import io.sage.modules.employer.service.PostService;
import io.sage.modules.sys.entity.SysUserEntity;


@Service("postService")
public class PostServiceImpl  implements PostService {
	
	@Autowired
	private PostMapper postMapper;
	
    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        return null;
    }

	@Override
	public PageUtils selectPostList(Map<String, Object> params) {
		
		Integer limit = Integer.parseInt((String)params.get("limit"));
    	Integer pageNum = Integer.parseInt((String)params.get("page"));
		
		Page<Post> page = new Page<>(pageNum,limit);
		page.setRecords(postMapper.selectPostList(page, params));
		
		return new PageUtils(page);
	}

	@Override
	public int insert(Post post,SysUserEntity user) {
		
		//如果获取不到值,就返回失败信息-1.
		Integer state=-1;
		
		if(!"".equals(user.getUserId())){
			//创建人.
			post.setUserId(user.getUserId().intValue());
		}else {
			return state;
		}
		if(!"".equals(user.getDeptId())){
			//设置部门id.
			post.setDeptId(user.getDeptId().intValue());
		}else {
			return state;
		}
		//创建日期.
		post.setCreateTime(new Date());
		//新增数据 数据状态(正常)设置为0.
		post.setDisFlag(ExamEnum.NOTRESULT.getCode());
		
		int insert = postMapper.insert(post);
		
		return insert;
	}

	@Override
	public Post selectById(Integer id) {
		
		return postMapper.selectByPrimaryKey(id);
		
	}

	@Override
	public int updateAllColumnById(Post post) {
		
		post.setUpdateTime(new Date());
		
		return postMapper.updateByPrimaryKeySelective(post);
	}

	@Override
	public int deleteBatchIds(Integer[] ids) {
		return postMapper.deleteBatchIds(ids);
	}

	@Override
	public List<Post> getPostList(Map<String, Object> params) {
		Page<Post> page=new Page<>();
		List<Post> selectPostList = postMapper.selectPostList(page, params);
		return selectPostList;
	}

}
